using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Abide_AddOn_API.Classes
{
    public static class Settings
    {
        #region Properties
        private static CustomSettings _custSettings = new CustomSettings();
        public static CustomSettings CustomSettings
        {
            get { return _custSettings; }
        }
        public static string AddOnsPath
        {
            get { return Settings.GetKey(@"Xbox\Halo2\Abide", "AddOns").ToString(); }
            set { Settings.SetKey(@"Xbox\Halo2\Abide", value, System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"Abide\AddOns"), false); }
        }
        public static string ThemesPath
        {
            get { return Settings.GetKey(@"Xbox\Halo2\Abide", "Themes").ToString(); }
            set { Settings.SetKey(@"Xbox\Halo2\Abide", value, System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"Abide\Themes"), false); }
        }

        public static string H2_PluginsPath
        {
            get { return Settings.GetKey(@"Xbox\Halo2\Paths", "Plugins").ToString(); }
            set { Settings.SetKey(@"Xbox\Halo2\Paths", "Plugins", value, true); if (PluginsPathChanged != null) PluginsPathChanged.Invoke(value, null); }
        }
        public static string H2_MainMenuPath
        {
            get { return Settings.GetKey(@"Xbox\Halo2\Paths", "MainMenu").ToString(); }

            set { Settings.SetKey(@"Xbox\Halo2\Paths", "MainMenu", value, true); }
        }
        public static string H2_SharedPath
        {
            get { return Settings.GetKey(@"Xbox\Halo2\Paths", "Shared").ToString(); }

            set { Settings.SetKey(@"Xbox\Halo2\Paths", "Shared", value, true); }
        }
        public static string H2_SinglePlayerSharedPath
        {
            get { return Settings.GetKey(@"Xbox\Halo2\Paths", "SPShared").ToString(); }

            set { Settings.SetKey(@"Xbox\Halo2\Paths", "SPShared", value, true); }
        }
        public static string H2B_PluginsPath
        {
            get { return Settings.GetKey(@"Xbox\Halo2 Beta\Paths", "Plugins").ToString(); }
            set { Settings.SetKey(@"Xbox\Halo2 Beta\Paths", "Plugins", value, true); if (PluginsPathChanged != null) PluginsPathChanged.Invoke(value, null); }
        }
        public static string H2B_MainMenuPath
        {
            get { return Settings.GetKey(@"Xbox\Halo2 Beta\Paths", "MainMenu").ToString(); }

            set { Settings.SetKey(@"Xbox\Halo2 Beta\Paths", "MainMenu", value, true); }
        }
        public static string H2B_SharedPath
        {
            get { return Settings.GetKey(@"Xbox\Halo2 Beta\Paths", "Shared").ToString(); }

            set { Settings.SetKey(@"Xbox\Halo2 Beta\Paths", "Shared", value, true); }
        }

        public static string UpdateThreshold
        {
            get { return Settings.GetKey(@"Xbox\Halo2\Abide", "UpdateThreshold").ToString(); }

            set { Settings.SetKey(@"Xbox\Halo2\Abide", "UpdateThreshold", value, true); }
        }
        public static string ModdedMapsPath
        {
            get { return Settings.GetKey(@"Xbox\Halo2\Paths", "Maps").ToString(); }

            set { Settings.SetKey(@"Xbox\Halo2\Paths", "Maps", value, true); }
        }
        public static string CleanMapsPath
        {
            get { return Settings.GetKey(@"Xbox\Halo2\Paths", "CleanMaps").ToString(); }

            set { Settings.SetKey(@"Xbox\Halo2\Paths", "CleanMaps", value, true); }
        }
        public static string ExtractFolderPath
        {
            get { return Settings.GetKey(@"Xbox\Halo2\Paths", "Extracts").ToString(); }

            set { Settings.SetKey(@"Xbox\Halo2\Paths", "Extracts", value, true); }
        }
        public static string DebugIp
        {
            get { return Settings.GetKey(@"Xbox", "Debug Ip").ToString(); }

            set { Settings.SetKey(@"Xbox", "Debug Ip", value, true); if (DebugIpChanged != null) DebugIpChanged.Invoke(value, null); }
        }
        public static string TagViewType_HCE
        {
            get { return Settings.GetKey(@"Xbox\HaloCE\Abide", "TagViewType").ToString(); }

            set { Settings.SetKey(@"Xbox\HaloCE\Abide", "TagViewType", value, true); }
        }
        public static string TagViewType_H2
        {
            get { return Settings.GetKey(@"Xbox\Halo2\Abide", "TagViewType").ToString(); }

            set { Settings.SetKey(@"Xbox\Halo2\Abide", "TagViewType", value, true); }
        }
        public static string TagViewType_H2B
        {
            get { return Settings.GetKey(@"Xbox\Halo2 Beta\Abide", "TagViewType").ToString(); }

            set { Settings.SetKey(@"Xbox\Halo2 Beta\Abide", "TagViewType", value, true); }
        }
        public static string TagViewType_H3
        {
            get { return Settings.GetKey(@"Xbox 360\Halo3\Abide", "TagViewType").ToString(); }

            set { Settings.SetKey(@"Xbox\Halo3\Abide", "TagViewType", value, true); }
        }
        public static string TagViewType_H3B
        {
            get { return Settings.GetKey(@"Xbox 360\Halo3 Beta\Abide", "TagViewType").ToString(); }

            set { Settings.SetKey(@"Xbox\Halo3 Beta\Abide", "TagViewType", value, true); }
        }
        public static string TagViewType_HR
        {
            get { return Settings.GetKey(@"Xbox 360\Halo Reach\Abide", "TagViewType").ToString(); }

            set { Settings.SetKey(@"Xbox\Halo Reach\Abide", "TagViewType", value, true); }
        }
        public static string FilterValue
        {
            get { return Settings.GetKey(@"Xbox\Halo2\Abide", "Filter").ToString(); }

            set { Settings.SetKey(@"Xbox\Halo2\Abide", "Filter", value, true); }
        }
        public static string LastTool
        {
            get { return Settings.GetKey(@"Xbox\Halo2\Abide", "LastTool").ToString(); }

            set { Settings.SetKey(@"Xbox\Halo2\Abide", "LastTool", value, true); }
        }
        public static string UseSwapperForm
        {
            get { return Settings.GetKey(@"Xbox\Halo2\Abide", "UseSwapperForm").ToString(); }

            set { Settings.SetKey(@"Xbox\Halo2\Abide", "UseSwapperForm", value, true); }
        }
        public static string EnablePokeHistory
        {
            get { return Settings.GetKey(@"Xbox\Halo2\Abide", "EnablePokeHistory").ToString(); }

            set { Settings.SetKey(@"Xbox\Halo2\Abide", "EnablePokeHistory", value, true); }
        }
        public static string AutoConnect
        {
            get { return Settings.GetKey(@"Xbox\Halo2\Abide", "AutoConnect").ToString(); }

            set { Settings.SetKey(@"Xbox\Halo2\Abide", "AutoConnect", value, true); }
        }
        public static List<string> RecentMaps_CE
        {
            get
            {
                //Create Dictionary to Return Values
                List<string> ReturnValue = new List<string>();

                //Open Software Key
                RegistryKey Software = Registry.CurrentUser.OpenSubKey("Software", false);

                if (Software != null)
                {
                    //Open Values Key
                    RegistryKey Pathskey = Software.OpenSubKey(@"Xbox\HaloCE\Recent Files", false);

                    if (Pathskey != null)
                    {
                        //Get registered values
                        string[] RegisteredPaths = Pathskey.GetValueNames();

                        //Loop through values
                        foreach (string valuename in RegisteredPaths)
                        {
                            //Get Value object
                            string Path = GetKey(@"Xbox\HaloCE\Recent Files", valuename).ToString();

                            //Add Value To Dictionary
                            ReturnValue.Add(Path);
                        }

                        //Close
                        Pathskey.Close();
                    }

                    //Close Keys
                    Software.Close();
                }

                return ReturnValue;
            }
            set
            {
                CreateRecentMapsKey();

                //Open Software Key
                RegistryKey Software = Registry.CurrentUser.OpenSubKey("Software", true);

                //Delete Key
                Software.DeleteSubKey(@"Xbox\HaloCE\Recent Files");

                //Open Values Key
                RegistryKey Valueskey = Software.CreateSubKey(@"Xbox\HaloCE\Recent Files");

                //Save Values Into Registry
                for (int i = 0; i < Math.Min(value.Count, 10); i++)
                {
                    SetKey(@"Xbox\HaloCE\Recent Files", i.ToString(), value[i], true);
                }

                //Close Values
                Valueskey.Close();
                Software.Close();
            }
        }
        public static List<string> RecentMaps_H2
        {
            get
            {
                //Create Dictionary to Return Values
                List<string> ReturnValue = new List<string>();

                //Open Software Key
                RegistryKey Software = Registry.CurrentUser.OpenSubKey("Software", false);

                if (Software != null)
                {
                    //Open Values Key
                    RegistryKey Pathskey = Software.OpenSubKey(@"Xbox\Halo2\Recent Files", false);

                    if (Pathskey != null)
                    {
                        //Get registered values
                        string[] RegisteredPaths = Pathskey.GetValueNames();

                        //Loop through values
                        foreach (string valuename in RegisteredPaths)
                        {
                            //Get Value object
                            string Path = GetKey(@"Xbox\Halo2\Recent Files", valuename).ToString();

                            //Add Value To Dictionary
                            ReturnValue.Add(Path);
                        }

                        //Close
                        Pathskey.Close();
                    }

                    //Close Keys
                    Software.Close();
                }

                return ReturnValue;
            }
            set
            {
                CreateRecentMapsKey();

                //Open Software Key
                RegistryKey Software = Registry.CurrentUser.OpenSubKey("Software", true);

                //Delete Key
                Software.DeleteSubKey(@"Xbox\Halo2\Recent Files");

                //Open Values Key
                RegistryKey Valueskey = Software.CreateSubKey(@"Xbox\Halo2\Recent Files");

                //Save Values Into Registry
                for (int i = 0; i < Math.Min(value.Count, 10); i++)
                {
                    SetKey(@"Xbox\Halo2\Recent Files", i.ToString(), value[i], true);
                }

                //Close Values
                Valueskey.Close();
                Software.Close();
            }
        }
        public static List<string> RecentMaps_H2B
        {
            get
            {
                //Create Dictionary to Return Values
                List<string> ReturnValue = new List<string>();

                //Open Software Key
                RegistryKey Software = Registry.CurrentUser.OpenSubKey("Software", false);

                if (Software != null)
                {
                    //Open Values Key
                    RegistryKey Pathskey = Software.OpenSubKey(@"Xbox\Halo2 Beta\Recent Files", false);

                    if (Pathskey != null)
                    {
                        //Get registered values
                        string[] RegisteredPaths = Pathskey.GetValueNames();

                        //Loop through values
                        foreach (string valuename in RegisteredPaths)
                        {
                            //Get Value object
                            string Path = GetKey(@"Xbox\Halo2 Beta\Recent Files", valuename).ToString();

                            //Add Value To Dictionary
                            ReturnValue.Add(Path);
                        }

                        //Close
                        Pathskey.Close();
                    }

                    //Close Keys
                    Software.Close();
                }

                return ReturnValue;
            }
            set
            {
                CreateRecentMapsKey();

                //Open Software Key
                RegistryKey Software = Registry.CurrentUser.OpenSubKey("Software", true);

                //Delete Key
                Software.DeleteSubKey(@"Xbox\Halo2 Beta\Recent Files");

                //Open Values Key
                RegistryKey Valueskey = Software.CreateSubKey(@"Xbox\Halo2 Beta\Recent Files");

                //Save Values Into Registry
                for (int i = 0; i < Math.Min(value.Count, 10); i++)
                {
                    SetKey(@"Xbox\Halo2 Beta\Recent Files", i.ToString(), value[i], true);
                }

                //Close Values
                Valueskey.Close();
                Software.Close();
            }
        }
        public static List<string> RecentMaps_H3
        {
            get
            {
                //Create Dictionary to Return Values
                List<string> ReturnValue = new List<string>();

                //Open Software Key
                RegistryKey Software = Registry.CurrentUser.OpenSubKey("Software", false);

                if (Software != null)
                {
                    //Open Values Key
                    RegistryKey Pathskey = Software.OpenSubKey(@"Xbox 360\Halo3\Recent Files", false);

                    if (Pathskey != null)
                    {
                        //Get registered values
                        string[] RegisteredPaths = Pathskey.GetValueNames();

                        //Loop through values
                        foreach (string valuename in RegisteredPaths)
                        {
                            //Get Value object
                            string Path = GetKey(@"Xbox 360\Halo3\Recent Files", valuename).ToString();

                            //Add Value To Dictionary
                            ReturnValue.Add(Path);
                        }

                        //Close
                        Pathskey.Close();
                    }

                    //Close Keys
                    Software.Close();
                }

                return ReturnValue;
            }
            set
            {
                CreateRecentMapsKey();

                //Open Software Key
                RegistryKey Software = Registry.CurrentUser.OpenSubKey("Software", true);

                //Delete Key
                Software.DeleteSubKey(@"Xbox 360\Halo3\Recent Files");

                //Open Values Key
                RegistryKey Valueskey = Software.CreateSubKey(@"Xbox 360\Halo3\Recent Files");

                //Save Values Into Registry
                for (int i = 0; i < Math.Min(value.Count, 10); i++)
                {
                    SetKey(@"Xbox 360\Halo3\Recent Files", i.ToString(), value[i], true);
                }

                //Close Values
                Valueskey.Close();
                Software.Close();
            }
        }
        public static List<string> RecentMaps_H3B
        {
            get
            {
                //Create Dictionary to Return Values
                List<string> ReturnValue = new List<string>();

                //Open Software Key
                RegistryKey Software = Registry.CurrentUser.OpenSubKey("Software", false);

                if (Software != null)
                {
                    //Open Values Key
                    RegistryKey Pathskey = Software.OpenSubKey(@"Xbox 360\Halo3 Beta\Recent Files", false);

                    if (Pathskey != null)
                    {
                        //Get registered values
                        string[] RegisteredPaths = Pathskey.GetValueNames();

                        //Loop through values
                        foreach (string valuename in RegisteredPaths)
                        {
                            //Get Value object
                            string Path = GetKey(@"Xbox 360\Halo3 Beta\Recent Files", valuename).ToString();

                            //Add Value To Dictionary
                            ReturnValue.Add(Path);
                        }

                        //Close
                        Pathskey.Close();
                    }

                    //Close Keys
                    Software.Close();
                }

                return ReturnValue;
            }
            set
            {
                CreateRecentMapsKey();

                //Open Software Key
                RegistryKey Software = Registry.CurrentUser.OpenSubKey("Software", true);

                //Delete Key
                Software.DeleteSubKey(@"Xbox 360\Halo3 Beta\Recent Files");

                //Open Values Key
                RegistryKey Valueskey = Software.CreateSubKey(@"Xbox 360\Halo3 Beta\Recent Files");

                //Save Values Into Registry
                for (int i = 0; i < Math.Min(value.Count, 10); i++)
                {
                    SetKey(@"Xbox 360\Halo3 Beta\Recent Files", i.ToString(), value[i], true);
                }

                //Close Values
                Valueskey.Close();
                Software.Close();
            }
        }
        public static List<string> RecentMaps_HR
        {
            get
            {
                //Create Dictionary to Return Values
                List<string> ReturnValue = new List<string>();

                //Open Software Key
                RegistryKey Software = Registry.CurrentUser.OpenSubKey("Software", false);

                if (Software != null)
                {
                    //Open Values Key
                    RegistryKey Pathskey = Software.OpenSubKey(@"Xbox 360\Halo Reach\Recent Files", false);

                    if (Pathskey != null)
                    {
                        //Get registered values
                        string[] RegisteredPaths = Pathskey.GetValueNames();

                        //Loop through values
                        foreach (string valuename in RegisteredPaths)
                        {
                            //Get Value object
                            string Path = GetKey(@"Xbox 360\Halo Reach\Recent Files", valuename).ToString();

                            //Add Value To Dictionary
                            ReturnValue.Add(Path);
                        }

                        //Close
                        Pathskey.Close();
                    }

                    //Close Keys
                    Software.Close();
                }

                return ReturnValue;
            }
            set
            {
                CreateRecentMapsKey();

                //Open Software Key
                RegistryKey Software = Registry.CurrentUser.OpenSubKey("Software", true);

                //Delete Key
                Software.DeleteSubKey(@"Xbox 360\Halo Reach\Recent Files");

                //Open Values Key
                RegistryKey Valueskey = Software.CreateSubKey(@"Xbox 360\Halo Reach\Recent Files");

                //Save Values Into Registry
                for (int i = 0; i < Math.Min(value.Count, 10); i++)
                {
                    SetKey(@"Xbox 360\Halo Reach\Recent Files", i.ToString(), value[i], true);
                }

                //Close Values
                Valueskey.Close();
                Software.Close();
            }
        }

        public static bool UseTagViewIcons
        {
            get { return (GetKey(@"Xbox\Halo2\Abide", "UseTVIcons").ToString().ToLower() == "true"); }
            set { SetKey(@"Xbox\Halo2\Abide", "UseTVIcons", value.ToString().ToLower(), true); }
        }
        public static string Theme
        {
            get { return GetKey(@"Xbox\Halo2\Abide", "Theme").ToString(); }
            set { SetKey(@"Xbox\Halo2\Abide", "Theme", value.ToString(), true); }
        }
        #endregion

        #region Event Handlers
        public static event EventHandler ValueVisibilityChanged;
        public static event EventHandler DebugIpChanged;
        public static event EventHandler PluginsPathChanged;
        #endregion

        #region Methods
        public static void CreateKeys()
        {
            CreateSharedKeys();
            CreateAbideValues();
        }
        public static void CreateAbideValues()
        {
            //AddOns and Themes
            SetKey(@"Xbox\Halo2\Abide", "AddOns", System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"Abide\AddOns"), false);
            SetKey(@"Xbox\Halo2\Abide", "Themes", System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"Abide\Themes"), false);

            //Tag Tree View Type Tags,Folders,Filtered
            SetKey(@"Xbox\HaloCE\Abide", "TagViewType", "TagType", false);
            SetKey(@"Xbox\Halo2\Abide", "TagViewType", "TagType", false);
            SetKey(@"Xbox\Halo2 Beta\Abide", "TagViewType", "TagType", false);
            SetKey(@"Xbox 360\Halo3\Abide", "TagViewType", "TagType", false);
            SetKey(@"Xbox 360\Halo3 Beta\Abide", "TagViewType", "TagType", false);
            SetKey(@"Xbox 360\Halo Reach\Abide", "TagViewType", "TagType", false);

            //Path Values
            SetKey(@"Xbox 360\Halo Reach\Paths", "Plugins", "Not Set", false);
            SetKey(@"Xbox 360\Halo Reach\Paths", "TagLists", "Not Set", false);
            SetKey(@"Xbox 360\Halo Reach\Paths", "StringLists", "Not Set", false);

            //TreeView Icons
            SetKey(@"Xbox\Halo2\Abide", "UseTVIcons", "true", false);

            //Default Theme
            SetKey(@"Xbox\Halo2\Abide", "Theme", "Default", false);

            //Updater
            SetKey(@"Xbox\Halo2\Abide", "UpdateThreshold", "Stable", false);
        }
        public static void CreateAbideValues(bool Overwrite)
        {
            //AddOns and Themes
            SetKey(@"Xbox\Halo2\Abide", "AddOns", System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"Abide\AddOns"), Overwrite);
            SetKey(@"Xbox\Halo2\Abide", "Themes", System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"Abide\Themes"), Overwrite);

            //Tag Tree View Type Tags,Folders,Filtered
            SetKey(@"Xbox\HaloCE\Abide", "TagViewType", "TagType", Overwrite);
            SetKey(@"Xbox\Halo2\Abide", "TagViewType", "TagType", Overwrite);
            SetKey(@"Xbox\Halo2 Beta\Abide", "TagViewType", "TagType", Overwrite);
            SetKey(@"Xbox 360\Halo3\Abide", "TagViewType", "TagType", Overwrite);
            SetKey(@"Xbox 360\Halo3 Beta\Abide", "TagViewType", "TagType", Overwrite);
            SetKey(@"Xbox 360\Halo Reach\Abide", "TagViewType", "TagType", Overwrite);

            //Path Values
            SetKey(@"Xbox 360\Halo Reach\Paths", "Plugins", "Not Set", Overwrite);
            SetKey(@"Xbox 360\Halo Reach\Paths", "TagLists", "Not Set", Overwrite);
            SetKey(@"Xbox 360\Halo Reach\Paths", "StringLists", "Not Set", Overwrite);

            //TreeView Icons
            SetKey(@"Xbox\Halo2\Abide", "UseTVIcons", "true", Overwrite);

            //Default Theme
            SetKey(@"Xbox\Halo2\Abide", "Theme", "Default", Overwrite);

            //Updater
            SetKey(@"Xbox\Halo2\Abide", "UpdateThreshold", "Stable", Overwrite);
        }
        public static void CreateSharedKeys()
        {
            //Software Key
            RegistryKey SoftwareKey = Registry.CurrentUser.OpenSubKey(@"Software", true);

            //Write Recent Maps Key
            CreateRecentMapsKey();

            //Debug Ip
            CreateDebugIpValue();

            //Path Values
            SetKey(@"Xbox\HaloCE\Paths", "Plugins", "Not Set", false);
            SetKey(@"Xbox\HaloCE\Paths", "Maps", "Not Set", false);
            SetKey(@"Xbox\HaloCE\Paths", "CleanMaps", "Not Set", false);

            SetKey(@"Xbox\Halo2\Paths", "Plugins", "Not Set", false);
            SetKey(@"Xbox\Halo2\Paths", "MainMenu", "Not Set", false);
            SetKey(@"Xbox\Halo2\Paths", "Shared", "Not Set", false);
            SetKey(@"Xbox\Halo2\Paths", "SPShared", "Not Set", false);

            SetKey(@"Xbox\Halo2 Beta\Paths", "Plugins", "Not Set", false);
            SetKey(@"Xbox\Halo2 Beta\Paths", "MainMenu", "Not Set", false);
            SetKey(@"Xbox\Halo2 Beta\Paths", "Shared", "Not Set", false);

            SetKey(@"Xbox 360\Halo3\Paths", "Plugins", "Not Set", false);
            SetKey(@"Xbox 360\Halo3\Paths", "MainMenu", "Not Set", false);
            SetKey(@"Xbox 360\Halo3\Paths", "Shared", "Not Set", false);
            SetKey(@"Xbox 360\Halo3\Paths", "SPShared", "Not Set", false);

            SetKey(@"Xbox 360\Halo3 Beta\Paths", "Plugins", "Not Set", false);
            SetKey(@"Xbox 360\Halo3 Beta\Paths", "MainMenu", "Not Set", false);
            SetKey(@"Xbox 360\Halo3 Beta\Paths", "Shared", "Not Set", false);
            SetKey(@"Xbox 360\Halo3 Beta\Paths", "SPShared", "Not Set", false);

            SetKey(@"Xbox 360\Halo Reach\Paths", "Plugins", "Not Set", false);
        }
        public static void CreateSharedKeys(bool Overwrite)
        {
            //Software Key
            RegistryKey SoftwareKey = Registry.CurrentUser.OpenSubKey(@"Software", true);

            //Write Recent Maps Key
            CreateRecentMapsKey();

            //Debug Ip
            CreateDebugIpValue();

            //Path Values
            SetKey(@"Xbox\HaloCE\Paths", "Plugins", "Not Set", Overwrite);
            SetKey(@"Xbox\HaloCE\Paths", "Maps", "Not Set", Overwrite);
            SetKey(@"Xbox\HaloCE\Paths", "CleanMaps", "Not Set", Overwrite);

            SetKey(@"Xbox\Halo2\Paths", "Plugins", "Not Set", Overwrite);
            SetKey(@"Xbox\Halo2\Paths", "MainMenu", "Not Set", Overwrite);
            SetKey(@"Xbox\Halo2\Paths", "Shared", "Not Set", Overwrite);
            SetKey(@"Xbox\Halo2\Paths", "SPShared", "Not Set", Overwrite);

            SetKey(@"Xbox\Halo2 Beta\Paths", "Plugins", "Not Set", Overwrite);
            SetKey(@"Xbox\Halo2 Beta\Paths", "MainMenu", "Not Set", Overwrite);
            SetKey(@"Xbox\Halo2 Beta\Paths", "Shared", "Not Set", Overwrite);

            SetKey(@"Xbox 360\Halo3\Paths", "Plugins", "Not Set", Overwrite);
            SetKey(@"Xbox 360\Halo3\Paths", "MainMenu", "Not Set", Overwrite);
            SetKey(@"Xbox 360\Halo3\Paths", "Shared", "Not Set", Overwrite);
            SetKey(@"Xbox 360\Halo3\Paths", "SPShared", "Not Set", Overwrite);

            SetKey(@"Xbox 360\Halo3 Beta\Paths", "Plugins", "Not Set", Overwrite);
            SetKey(@"Xbox 360\Halo3 Beta\Paths", "MainMenu", "Not Set", Overwrite);
            SetKey(@"Xbox 360\Halo3 Beta\Paths", "Shared", "Not Set", Overwrite);
            SetKey(@"Xbox 360\Halo3 Beta\Paths", "SPShared", "Not Set", Overwrite);

            SetKey(@"Xbox 360\Halo Reach\Paths", "Plugins", "Not Set", Overwrite);
        }
        private static void CreateRecentMapsKey()
        {
            //Software Key
            RegistryKey SoftwareKey = Registry.CurrentUser.OpenSubKey(@"Software", true);

            //Open / create
            RegistryKey RecentFilesCE = SoftwareKey.CreateSubKey(@"Xbox\HaloCE\Recent Files");
            RegistryKey RecentFilesH2 = SoftwareKey.CreateSubKey(@"Xbox\Halo2\Recent Files");
            RegistryKey RecentFilesH2B = SoftwareKey.CreateSubKey(@"Xbox\Halo2 Beta\Recent Files");
            RegistryKey RecentFilesH3 = SoftwareKey.CreateSubKey(@"Xbox 360\Halo3\Recent Files");
            RegistryKey RecentFilesH3B = SoftwareKey.CreateSubKey(@"Xbox 360\Halo3 Beta\Recent Files");
            RegistryKey RecentFilesHR = SoftwareKey.CreateSubKey(@"Xbox 360\Halo Reach\Recent Files");
        }
        public static void CreateDebugIpValue()
        {
            //Ip
            SetKey("Xbox", "Debug Ip", "<Auto>", false);

            SetKey("Xbox 360", "Debug Ip", "0.0.0.0", false);
        }
        public static void ChangeVisibleValue(string ValueName, bool Value)
        {
            //Change Value
            SetKey(@"Xbox\Halo2\Abide\Visible Values", ValueName, Value, true);

            //invoke Event
            if (ValueVisibilityChanged != null)
                ValueVisibilityChanged.Invoke(ValueName, null);
        }
        public static object GetKey(string key, string valuename)
        {
            object KeyValue = null;

            //Get Software Key
            RegistryKey SoftwareKey = Registry.CurrentUser.CreateSubKey(@"Software", RegistryKeyPermissionCheck.Default);

            //Get Key
            RegistryKey Key = SoftwareKey.CreateSubKey(key);

            //Check if Key is Null
            if (Key == null)
                Key = SoftwareKey.CreateSubKey(key, RegistryKeyPermissionCheck.Default);

            //Get Key Value
            KeyValue = Key.GetValue(valuename);

            //Close Keys
            Key.Close();

            SoftwareKey.Close();

            return KeyValue;
        }
        public static void SetKey(string key, string valuename, object value, bool overwrite)
        {
            //Create Software Key
            RegistryKey SoftwareKey = Registry.CurrentUser.CreateSubKey(@"Software", RegistryKeyPermissionCheck.Default);

            //Open Key
            RegistryKey Key = SoftwareKey.CreateSubKey(key, RegistryKeyPermissionCheck.Default);

            //Check if Key is Null
            if (Key == null)
                Key = SoftwareKey.CreateSubKey(key);

            //Get Value Names
            string[] Keys = Key.GetValueNames();

            //Overwrite if value exists and overwrite is true
            if (Keys.Contains(valuename) && overwrite)
                Key.SetValue(valuename, value);

            //Create the value if it doesn't exist
            if (!Keys.Contains(valuename))
                Key.SetValue(valuename, value);


            //Close Keys
            Key.Close();

            SoftwareKey.Close();
        }
        #endregion
    }

    public class CustomSettings
    {
        public object this[string name]
        {
            get
            {
                return Settings.GetKey(@"Xbox\Halo2\Abide", name);
            }
            set
            {
                Settings.SetKey(@"Xbox\Halo2\Abide", name, value, true);
            }
        }
        public object this[string subFolder, string name]
        {
            get
            {
                return Settings.GetKey(string.Format(@"Xbox\Halo2\Abide\{0}", subFolder), name);
            }
            set
            {
                Settings.SetKey(string.Format(@"Xbox\Halo2\Abide\{0}", subFolder), name, value, true);
            }
        }
    }
}
